/*
 * Copyright (c) 2012 swing-on-fire Team
 * 
 * This file is part of Swing-On-Fire (http://code.google.com/p/swing-on-fire), licensed under the terms of the MIT
 * License (MIT).
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package com.google.code.swingonfire.showcase.component.page;

import static com.google.code.swingonfire.builder.JComponentBuilders.*;

import java.awt.Color;
import java.awt.event.ActionEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;

import com.google.code.eventsonfire.Events;
import com.google.code.eventsonfire.awt.AWTEvents;
import com.google.code.eventsonfire.swing.SwingEventHandler;
import com.google.code.swingonfire.component.ButtonPanel;
import com.google.code.swingonfire.component.page.JPagePane;
import com.google.code.swingonfire.showcase.TitlePanel;

public class JPagePaneShowcase extends AbstractJPageComponentShowcase<JPagePane>
{

    private static final long serialVersionUID = -1664314837619074615L;

    public JPagePaneShowcase()
    {
        super();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected TitlePanel createTitlePanel()
    {
        return new TitlePanel(
            "JPagePane",
            "A component, that displays a list of other components. The transition between components is animated.\n"
                + "The difference to the JPageComponent is, that the JPagePane holds a list components, but the JPageComponent just holds one component.");
    }

    @Override
    protected JPagePane createPageComponent()
    {
        JPagePane result = new JPagePane();

        result.setComponentProvider(new JPagePaneSampleProvider());
        result.setComponentIndexRange(Integer.MIN_VALUE, Integer.MAX_VALUE);
        result.setSelectedComponentIndex(0, false);

        return result;
    }

    @Override
    protected JPanel createNavigationPanel()
    {
        JButton previous10Button =
            Events.bind(
                buttonBuilder().text("Previous 10").listener("previous10", AWTEvents.fireOnAction()).opaque(false)
                    .build(), this);
        JButton previousButton =
            Events.bind(buttonBuilder().text("Previous").listener("previous", AWTEvents.fireOnAction()).opaque(false)
                .build(), this);
        JButton nextButton =
            Events.bind(buttonBuilder().text("Next").listener("next", AWTEvents.fireOnAction()).opaque(false).build(),
                this);
        JButton next10Button =
            Events.bind(buttonBuilder().text("Next 10").listener("next10", AWTEvents.fireOnAction()).opaque(false)
                .build(), this);

        JPanel result = new ButtonPanel().left(previous10Button, previousButton).right(nextButton, next10Button);

        result.setBorder(BorderFactory.createEmptyBorder(8, 12, 8, 12));
        result.setBackground(Color.WHITE);
        result.setOpaque(true);

        return result;
    }

    @SwingEventHandler(event = ActionEvent.class, eachTag = "previous")
    public void onPrevioius()
    {
        getPageComponent().setSelectedComponentIndex(getPageComponent().getSelectedComponentIndex() - 1);
    }

    @SwingEventHandler(event = ActionEvent.class, eachTag = "previous10")
    public void onPrevioius10()
    {
        getPageComponent().setSelectedComponentIndex(getPageComponent().getSelectedComponentIndex() - 10);
    }

    @SwingEventHandler(event = ActionEvent.class, eachTag = "next")
    public void onNext()
    {
        getPageComponent().setSelectedComponentIndex(getPageComponent().getSelectedComponentIndex() + 1);
    }

    @SwingEventHandler(event = ActionEvent.class, eachTag = "next10")
    public void onNext10()
    {
        getPageComponent().setSelectedComponentIndex(getPageComponent().getSelectedComponentIndex() + 10);
    }

}
